home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / text / hyper / hsc_source.lha / hsc / source / ugly / umemory.h < prev    next >
C/C++ Source or Header  |  1996-07-30  |  3KB  |  83 lines

  1. #ifndef UGLY_UMEMORY_H
  2. #define UGLY_UMEMORY_H           /* avoid include twice */
  3.  
  4. /*
  5.  * ugly/umemory.h
  6.  *
  7.  * additional memory manegment, tracking and debugging functions, header file
  8.  *
  9.  */
  10.  
  11. #include <stdlib.h>
  12.  
  13. #include "utypes.h"
  14.  
  15. /*
  16.  * ufree() - macro to free memory and set var
  17.  *           pointing to memory to NULL,
  18.  *           but only if it has been allocated
  19.  *           successfully before
  20.  */
  21. typedef struct uglymem {
  22.  
  23.     struct uglymem *next;
  24.     void *ptr;                  /* ptr to mem area allocated before */
  25.     STRPTR lower;               /* lower wall */
  26.     STRPTR upper;               /* upper wall */
  27.     size_t size;                /* size of this area */
  28.     STRPTR file;                /* filename from which call came */
  29.     ULONG line;                 /* line num in this file */
  30.     UBYTE fillchar;             /* fill character for wall */
  31.  
  32. } UGLYMEM;
  33.  
  34. #if DEBUG_UGLY_MEMORY
  35.  
  36. /* ugly function calls with memory tracking ENABLED */
  37. #define umalloc(size) ugly_malloc_tracking( size, __FILE__, __LINE__ )
  38. #define ufree(ptr)    if ( ptr ) { ugly_free( ptr, __FILE__, __LINE__ ); ptr = NULL; }
  39. #define urealloc(ptr,size) ugly_realloc( ptr, size, __FILE, __LINE__ );
  40. #define ucalloc(count,size) ugly_calloc( count,size,__FILE__,__LINE );
  41.  
  42. #define umem_report(msg) uglymem_report( msg, __FILE__, __LINE__, __DATE__, __TIME__ )
  43. #define umem_stats(msg) uglymem_stats( msg, __FILE__, __LINE__, __DATE__, __TIME__ )
  44. #define umem_wallcheck(msg) uglymem_wallcheck( msg, __FILE__, __LINE__ )
  45.  
  46. #define atexit_uglymemory atexit_uglymemory_real
  47.  
  48. #else
  49.  
  50. /* ugly function calls with memory tracking disabled */
  51. #define umalloc(size) ugly_malloc_notracking(size)
  52. #define ufree(ptr)    if ( ptr ) { free(ptr); ptr=NULL; }       /* TODO: use only free() */
  53. #define urealloc(ptr,size)  realloc( ptr, size );
  54. #define ucalloc(count,size) calloc( count,size )
  55.  
  56. #define umem_report(msg)        /* nufin */
  57. #define umem_stats(msg)         /* nufin */
  58. #define umem_wallcheck(msg)     /* nufin */
  59.  
  60. #define atexit_uglymemory atexit_uglymemory_dummy
  61.  
  62. #endif /* DEBUG_UGLY_MEMORY */
  63.  
  64. #ifndef NOEXTERN_UGLY_UMEMORY_H
  65.  
  66. extern void *ugly_malloc_tracking(size_t size, STRPTR file, ULONG line);
  67. extern void *ugly_malloc_notracking(size_t size);
  68. extern void ugly_free(void *ptr, STRPTR file, ULONG line);
  69. extern void *ugly_realloc(void *ptr, size_t size, STRPTR file, ULONG line);
  70. extern void *ugly_calloc(size_t count, size_t size, STRPTR file, ULONG line);
  71.  
  72. extern void uglymem_stats(STRPTR msg, STRPTR file, ULONG line, STRPTR date, STRPTR time);
  73. extern void uglymem_report(STRPTR msg, STRPTR file, ULONG line, STRPTR date, STRPTR time);
  74. extern void uglymem_wallcheck(STRPTR msg, STRPTR file, ULONG line);
  75. extern void atexit_uglymemory(void);
  76.  
  77. extern BOOL(*ugly_nomem_handler) (size_t size);
  78.  
  79. #endif
  80.  
  81. #endif
  82.  
  83.